﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;

namespace MemoDb
{
    public class MemoQuery<T> : IQueryable<T>
    {
        private readonly Func<IEnumerable<T>> getCurrentItems;

        public MemoQuery(Func<IEnumerable<T>> getCurrentItems)
        {
            this.getCurrentItems = getCurrentItems;
        }

        public IEnumerator<T> GetEnumerator()
        {
            return getCurrentItems().GetEnumerator();
        }

        IEnumerator IEnumerable.GetEnumerator()
        {
            return GetEnumerator();
        }

        public Expression Expression
        {
            get { return getCurrentItems().AsQueryable().Expression; }
        }

        public Type ElementType
        {
            get { return typeof (T); }
        }

        public IQueryProvider Provider
        {
            get { return getCurrentItems().AsQueryable().Provider; }
        }
    }
}